package logic

import (
	"context"
	"errors"
	"gorm.io/gorm"
	"user_srv/model/mysql"

	"user_srv/internal/svc"
	"user_srv/user"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetUserRealNameByIdCardLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGetUserRealNameByIdCardLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUserRealNameByIdCardLogic {
	return &GetUserRealNameByIdCardLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GetUserRealNameByIdCardLogic) GetUserRealNameByIdCard(in *user.GetUserInfoByIdCardRequest) (*user.GetUserInfoByIdCardResponse, error) {
	// todo: add your logic here and delete this line
	ur := mysql.UserRealName{
		IdCard: in.IdCard,
	}
	err := ur.GetUserRealNameByIdCard()
	if err != nil && errors.Is(err, gorm.ErrRecordNotFound) {
		logx.Error("获取实名信息失败", err)
		return nil, err
	}
	return &user.GetUserInfoByIdCardResponse{UserId: int64(ur.UserId)}, nil
}
